<?php

/**
 * This is the model class for table "dkpchar".
 *
 * The followings are the available columns in table 'dkpchar':
 * @property integer $characterId
 * @property integer $earned
 * @property integer $spent
 * @property integer $adjustment
 * @property integer $statusId
 * @property string $firstRaid
 * @property string $lastRaid
 * @property integer $raidCount
 *
 * The followings are the available model relations:
 * @property Character $character
 * @property Status $status
 */
class Dkpchar extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Dkpchar the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'dkpchar';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('characterId', 'required'),
			array('characterId, earned, spent, adjustment, statusId, raidCount', 'numerical', 'integerOnly'=>true),
			array('firstRaid, lastRaid', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('characterId, earned, spent, adjustment, statusId, firstRaid, lastRaid, raidCount', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'character' => array(self::BELONGS_TO, 'Character', 'characterId'),
			'status' => array(self::BELONGS_TO, 'Status', 'statusId'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'characterId' => 'Character',
			'earned' => 'Earned',
			'spent' => 'Spent',
			'adjustment' => 'Adjustment',
			'statusId' => 'Status',
			'firstRaid' => 'First Raid',
			'lastRaid' => 'Last Raid',
			'raidCount' => 'Raid Count',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('characterId',$this->characterId);
		$criteria->compare('earned',$this->earned);
		$criteria->compare('spent',$this->spent);
		$criteria->compare('adjustment',$this->adjustment);
		$criteria->compare('statusId',$this->statusId);
		$criteria->compare('firstRaid',$this->firstRaid,true);
		$criteria->compare('lastRaid',$this->lastRaid,true);
		$criteria->compare('raidCount',$this->raidCount);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}